/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @addtogroup feature_processor
 * @{
 *
 * @brief Defines the basic functions for FeatureProcessor, including the supported data types
 * and other related configuration parameters.
 *
 * @since 2.2
 * @version 1.0
 */

/**
 * @file feature_processor.h
 *
 * @brief Defines basic functions for FeatureProcessor, including the supported data types
 * and other related configuration paramters.
 *
 * @since 2.2
 * @version 1.0
 */

#ifndef AUDIO_PREPROCESS_FEATURE_PROCESSOR_H
#define AUDIO_PREPROCESS_FEATURE_PROCESSOR_H

#include <cstdint>
#include <string>

namespace OHOS {
namespace AI {
namespace Feature {
/**
 *
 * @brief Defines the maximum number of channels for the frequency-domain features generated by FeatureProcessor.
 *
 * @since 2.2
 * @version 1.0
 */
#define MAX_NUM_CHANNELS 100

/**
 *
 * @brief Defines the maximum number of samples supported by FeatureProcessor.
 *
 * @since 2.2
 * @version 1.0
 */
#define MAX_SAMPLE_SIZE 20000

/**
 *
 * @brief Defines the number of bytes based on the data type.
 *
 * @since 2.2
 * @version 1.0
 */
#define CONVERT_DATATYPE_TO_SIZE(x) static_cast<uint8_t>(x & 7)

/**
 *
 * @brief Defines the data structures supported by FeatureProcessor.
 *
 * @since 2.2
 * @version 1.0
 */
enum DataType {
    UINT8  = 1,
    UINT16 = 2,
    UINT32 = 4,
    INT8   = 1 | (1 << 3),
    INT16  = 2 | (1 << 3),
    INT32  = 4 | (1 << 3),
    FLOAT  = 4 | (1 << 4),
    UNKNOWN,
};

/**
 *
 * @brief Specifies the structure for the FeatureProcessor configuration.
 *
 * @since 2.2
 * @version 1.0
 */
struct FeatureProcessorConfig {
    /** Data types supported by FeatureProcessor. For details, see {@link DataType}. */
    DataType dataType = UNKNOWN;
};

/**
 *
 * @brief Defines the basic structure for the data to be processed by FeatureProcessor.
 *
 * @since 2.2
 * @version 1.0
 */
struct FeatureData {
    /** Type of feature data. For details, see {@link DataType}. */
    DataType dataType;
    /** Start address of feature data */
    void *data;
    /** Length of feature data */
    size_t size;
};

/**
 *
 * @brief Defines basic functions for FeatureProcessor.
 *
 * @since 2.2
 * @version 1.0
 */
class FeatureProcessor {
public:
    /**
     * @brief Defines the destructor for FeatureProcessor.
     *
     * @since 2.2
     * @version 1.0
     */
    virtual ~FeatureProcessor() = default;

    /**
     * @brief Initializes FeatureProcessor.
     *
     * @param config Indicates the pointer to the basic configuration of FeatureProcessor.
     * The caller needs to pass in a pointer address defined by {@link FeatureProcessorConfig}
     * and release the pointer after using it.
     * @return Returns {@link RETCODE_SUCCESS} if the operation is successful;
     * returns {@link RETCODE_FAILURE} otherwise.
     *
     * @since 2.2
     * @version 1.0
     */
    virtual int32_t Init(const FeatureProcessorConfig *config) = 0;

    /**
     * @brief Performs feature processing.
     *
     * @param input Indicates the input data for FeatureProcessor. The caller must pass in FeatureData
     * of the type defined by {@link DataType}.
     * @param output Indicates the output data for FeatureProcessor. The caller must pass in FeatureData
     * of the type defined by {@link DataType}. If and only if its address is empty and the data length is <b>0</b>,
     * data will be filled by the FeatureProcessor.
     * @return Returns {@link RETCODE_SUCCESS} if the operation is successful;
     * returns {@link RETCODE_FAILURE} otherwise.
     *
     * @since 2.2
     * @version 1.0
     */
    virtual int32_t Process(const FeatureData &input, FeatureData &output) = 0;

    /**
     * @brief Releases resources.
     *
     * @since 2.2
     * @version 1.0
     */
    virtual void Release() = 0;
};
} // namespace Feature
} // namespace AI
} // namespace OHOS
#endif // AUDIO_PREPROCESS_FEATURE_PROCESSOR_H
/** @} */